<template>
  <div style="width: 100%;height: 100%;">
    <el-container style="width: 100%;height: 100%;">
      <!-- 头部去 -->
      <el-header>
        <el-row >
          <el-col :span="11">
            logo
          </el-col>
          <el-col :span="11">
            <!-- <h1> -->
            电商后台管理系统
            <!-- </h1> -->
          </el-col>
          <el-col :span="2">
            <el-button type="danger" @click="tc">退出登录</el-button>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <!-- 做菜单栏 -->
        <el-aside :width="isCollapse?'60px':'200px'">
          <div
            class="box"
            @click="isCollapse=!isCollapse"
          >
            <i class="el-icon-s-unfold"></i>
          </div>
          <el-menu
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
            :router="true"
            :collapse="isCollapse"
            :collapse-transition="false"
          >
            <el-submenu
              :index="index+''"
              v-for="(item,index) in menus"
              :key="index"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item-group
                v-for="(itm,ind) in item.children"
                :key="ind"
              >
                <el-menu-item :index="'/'+itm.path">{{itm.authName}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menus: [],
      isCollapse: false
    };
  },
  created() {
    this.xr();
    console.log("11", this.$route.path);
  },
  methods: {
    async xr() {
      let res = await this.$API.zuocecaidan();
      // console.log("左侧菜单渲染", res);
      this.menus = res;
    },
    tc() {
      this.$router.push("/login");
      sessionStorage.removeItem("token");
    }
  }
};
</script>

<style scoped >
.el-header {
  background: #333744;
  width: 100%;
  font-size: 30px;
  color: white;
  /* line-height: 60px; */
  /* display: flex */
}
.el-row{
  height: 100%;
  display: flex;
  align-items: center
}
.el-aside {
  background: #333744;
  height: 100%;
}
.box {
  width: 100%;
  /* background: orange; */
  height: 30px;
  text-align: center;
  line-height: 30px;
  font-size: 18px;
  color: white;
}
</style>